package cn.edu.scau.cmi.linhongyu.composite.consistent;

import java.net.URL;
import java.util.Iterator;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;


public class ConsistentCompositeController {
	ConsistentComposite team = null;
	String name = null;
    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private Button addTeam;

    @FXML
    private Button addperson;

    @FXML
    private TextField input;

    @FXML
    private TextArea msg;


    @FXML
    void initialize() {

    }
    
    @FXML
    void addPerson() {
    	ConsistentLeaf person = new ConsistentLeaf();
    	name = input.getText();
    	person.setName(name);
    	team.addChild(person);
    	msg.setText("团队名："+team.getName()+'\n');
    	Iterator<ConsistentComponent> temp = team.getChildren().iterator();
    	while(temp.hasNext()){
			ConsistentComponent disp = temp.next();
	    	if(disp instanceof ConsistentLeaf){
	    		ConsistentLeaf leaf = ((ConsistentLeaf)disp);
	    		System.out.println();
	    		System.out.print("\t成员："+leaf.getName()+'\n');
	    		msg.appendText("\t成员："+leaf.getName()+'\n');
	    	}
		}
    }
    
    @FXML
    void addTeam() {
    	team = new ConsistentComposite();
    	name = input.getText();
    	team.setName(name);
    	System.out.printf("团队名：%s",team.getName());
    	msg.setText("团队名："+team.getName()+'\n');
    	Iterator<ConsistentComponent> temp = team.getChildren().iterator();
		while(temp.hasNext()){
			ConsistentComponent disp = temp.next();
	    	if(disp instanceof ConsistentLeaf){
	    		ConsistentLeaf leaf = ((ConsistentLeaf)disp);
	    		System.out.println();
	    		System.out.print("\t成员："+leaf.getName());
	    		msg.appendText("\t成员："+leaf.getName()+'\n');
	    	}
		}
    }
}
